﻿using RayDen.Library.Core.Noise;
using RayDen.Library.Core.Primitives;
using RayDen.Library.Entity.Scene;

namespace RayDen.Library.Data
{
    public abstract class BaseProceduralTexture : ITexture
    {
        private int width, height;

        public UV DUDV { get; set; }
        public int Width
        {
            get { return width; }
        }

        public int Height
        {
            get { return height; }
        }
        protected BaseProceduralTexture(int w, int h)
        {
            this.width = w;
            this.height = h;
            DUDV = new UV(
                1f/Width,
                1f/Height);
        }
        public abstract RgbSpectrumInfo Sample(float u, float v);
        public float SampleFloat(float u, float v)
        {
            return this.Sample(u, v).y();
        }

        public virtual void Dispose()
        {
            
        }
    }


    public class NoiseTexture : BaseProceduralTexture
    {
        protected RgbSpectrum col;
        public NoiseTexture(int w, int h, RgbSpectrum color) : base(w, h)
        {
            col = color;
        }

        public override RgbSpectrumInfo Sample(float u, float v)
        {
            return col * new RgbSpectrumInfo(NoiseProvider.Instance.Noise3D(new Vector(u, v, 1f - u - v)));
        }
    }
}